package com.zsl.controller;

import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "Quit", urlPatterns = "/quit")
public class Quit extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //清除session
        HttpSession session = request.getSession();
        session.removeAttribute("user");
        session.removeAttribute("loginTime");
        //重定向
        Map<String, Object> res = new HashMap<>();
        res.put("redirect", "./");
        res.put("code", "1");
        PrintWriter out = response.getWriter();
        out.write(JSON.toJSONString(res));
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
